# 1、随机整数生成类
# 可以先设定一批生成数字的个数，可设定指定生成的数值的范围。运行时还可以调整每批生成数字的个数
import random

class random_number:
    def __init__(self,start_num=0,stop_num=100,count_num=10):
        self.start_num = start_num
        self.stop_num = stop_num
        self.count_num = count_num

    def generate(self):
        return [random.randint(self.start_num,self.stop_num) for i in range(self.count_num)]

ran_num = random_number(count_num=30)
print(ran_num.generate())

# 2、打印坐标
# 使用上题中的类，随机生成20个数字，两两配对形成二维坐标系的坐标，把这些坐标组织起来，并打印输出
import random
class random_number:
    '''定义坐标的值'''
    def __init__(self,start_num=0,stop_num=100,count_num=10):
        self.start_num = start_num
        self.stop_num = stop_num
        self._count_num = count_num
        self._ran_num = self.__ran_num() #定义随机数函数

    def __ran_num(self):
        while True: #定义生成器函数，调用一次迭代一次
            yield [random.randint(self.start_num,self.stop_num) for i in range(self._count_num)]

    def ran_num(self): #定义函数，可返回_ran_num
        return next(self._ran_num)

    @property #定义属性装饰器
    def count(self): #只读，取，getter
        return self._count_num
    @count.setter #实现可写
    def count(self,value):
        self._count_num = value
class coordinate:
    '''定义坐标类'''
    def __init__(self,x,y): #定义横坐标和纵坐标
        self.x = x
        self.y = y

    def __repr__(self):
        return '坐标值为:({},{})'.format(self.x,self.y)

# 坐标值实例化
co_value = random_number()
dots = [coordinate(x,y) for x,y in zip(co_value.ran_num(),co_value.ran_num())]
for zuobiao in dots:
    print(zuobiao)


